#!/bin/sh
# firewall-cmd --zone=public --add-port={3000/tcp,9090/tcp} --permanent
# firewall-cmd --reload
# 创建存储卷,启动MongoDB
docker volume create mongo-yapi-data
docker run -d --name mongo-yapi -v mongo-yapi-data:/data/db mongo:4.4.4

# 使用本目录下的Dockerfile构建镜像
# 可按需修改配置文件，默认 admin@admin.com/ymfe.org
docker build -t yapi-dir-img .

# 初始化数据库
docker run -it --rm \
  --link mongo-yapi:mongo \
  --entrypoint npm \
  --workdir /yapi/vendors \
  -v $PWD/config.json:/yapi/config.json \
  yapi-dir-img \
  run install-server

# 启动容器
docker run -d \
  --name mongo-yapi-site \
  --link mongo-yapi:mongo \
  --workdir /yapi/vendors \
  -p 3000:3000 \
  -v $PWD/config.json:/yapi/config.json \
  yapi-dir-img \
  server/app.js

# 重启时mongo-yapi,mongo-yapi-site两个容器先后启动即可
# 如果删除重建，确保删除mongo-yapi-data中旧数据
